package com.class06;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.invoke.VarHandle;
import java.util.Arrays;

@WebServlet("/servletB")
public class ServletB extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Cookie[] cookies = req.getCookies();
//        for (Cookie cookie : cookies) {
//            String name = cookie.getName();
//            String value = cookie.getValue();
//            System.out.println(name+"--"+value);
//        }
        Arrays.stream(cookies).
                forEach(cookie -> System.out.
                        println(cookie.getName() + "--" + cookie.getValue()));
        int[] arr = {1,2,3,4,5,6,5,7,8};

        Arrays.stream(arr).forEach(System.out::println);
//        for (int i = 0; i < arr.length; i++) {
//            System.out.println(arr[i]);
//        }
//        取出数组中第一个元素 findFirst()取出的第一个元素
        Arrays.stream(arr).findFirst().ifPresent(System.out::println);



    }
}
